﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>TrayTip - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The TrayTip function creates a balloon message window near the tray icon. On Windows 10, a toast notification may be shown instead." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>TrayTip</h1>

<p>Creates a balloon message window near the tray icon. On Windows 10, a toast notification may be shown instead.</p>

<pre class="Syntax"><span class="func">TrayTip</span> <span class="optional">Text, Title, Options</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>Text</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The message to display. Only the first 265 characters will be displayed.</p>
    <p>Carriage return (`r) or linefeed (`n) may be used to create multiple lines of text. 例如: <code>Line1`nLine2</code>.</p>
    <p>如果 <em>Text</em> 较长, 可以通过<a href="../Scripts.htm#continuation">延续片段</a>的方法将其分解成较短的几行, 这样可以增加可读性和可维护性.</p>
    <p>It is possible to show a window with only a title by leaving <em>Text</em> blank.</p>
  </dd>

  <dt>Title</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The title of the window. Only the first 73 characters will be displayed.</p>
    <p>If <em>Title</em> is blank, the title line will be entirely omitted from the window, making it vertically shorter.</p>
  </dd>

  <dt>Options</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a>或<a href="../Concepts.htm#numbers">整数</a></p>
    <p>Either an integer value (a combination by addition or bitwise-OR) or a string of zero or more case-insensitive options separated by at least one space or tab. One or more numeric options may also be included in the string.</p>
    <table class="info">
      <tr>
        <th>String</th>
        <th>Dec</th>
        <th>Hex</th>
        <th>Description</th>
      </tr>
      <tr>
        <td>Iconi</td>
        <td>1</td>
        <td>0x1</td>
        <td>Displays an info icon.</td>
      </tr>
      <tr>
        <td>Icon!</td>
        <td>2</td>
        <td>0x2</td>
        <td>Displays a warning icon.</td>
      </tr>
      <tr>
        <td>Iconx</td>
        <td>3</td>
        <td>0x3</td>
        <td>Displays an error icon.</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>4</td>
        <td>0x4</td>
        <td>Displays the current <a href="TraySetIcon.htm">tray icon</a>. Use 0x24 to display the large version of the tray icon. On Windows 10, the small tray icon is generally displayed even if this flag is omitted, and specifying this flag may cause the program's name to be shown in the notification.</td>
      </tr>
      <tr>
        <td>Mute</td>
        <td>16</td>
        <td>0x10</td>
        <td>Do not play the notification sound.</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>32</td>
        <td>0x20</td>
        <td>Use the large version of the icon.</td>
      </tr>
    </table>
    <p>If omitted, it defaults to 0, which is no icon. The icon is also not shown by the balloon window if it lacks a <em>Title</em> (this does not apply to Windows 10 toast notifications).</p>
    </dd>

</dl>

<h2>To Hide the Window</h2>
<p>To hide a TrayTip balloon window, omit both <em>Text</em> and <em>Title</em>. 例如:</p>
<pre>TrayTip</pre>
<p>To hide a Windows 10 toast notification, temporarily remove the tray icon. 例如:</p>
<pre>TrayTip "#1", "This is TrayTip #1"
Sleep 3000   <em>; Let it display for 3 seconds.</em>
HideTrayTip
TrayTip "#2", "This is the second notification."
Sleep 3000

<em id="Hide">; Copy this function into your script to use it.</em>
HideTrayTip() {
    TrayTip  <em>; Attempt to hide it the normal way.</em>
    if SubStr(A_OSVersion,1,3) = "10." {
        A_IconHidden := true
        Sleep 200  <em>; It may be necessary to adjust this sleep.</em>
        A_IconHidden := false
    }
}
</pre>
<p>This may not always work, according to at least one report.</p>

<h2 id="Remarks">备注</h2>
<p>On Windows 10, a TrayTip window usually looks like this:</p>
<img src="../static/dlg_traytip.png" alt="TrayTip" />
<p id="Windows10"><strong>Windows 10</strong> replaces all balloon windows with toast notifications by default (this can be overridden via group policy). Calling TrayTip multiple times will usually cause multiple notifications to be placed in a "queue" instead of each notification replacing the last.</p>
<p>TrayTip has no effect if the script lacks a tray icon (via <a href="_NoTrayIcon.htm">#NoTrayIcon</a> or <a href="../Variables.htm#IconHidden">A_IconHidden := true</a>). TrayTip also has no effect if the following REG_DWORD value exists and has been set to 0:</p>
<pre>HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced &gt;&gt; EnableBalloonTips</pre>
<p>On a related note, there is a tooltip displayed whenever the user hovers the mouse over the script's tray icon. The contents of this tooltip can be changed via: <code><a href="../Variables.htm#IconTip">A_IconTip</a> := "My New Text"</code>.</p>

<h2 id="Related">相关</h2>
<p><a href="ToolTip.htm">ToolTip</a>, <a href="SetTimer.htm">SetTimer</a>, <a href="../objects/Menu.htm">Menu object</a>, <a href="MsgBox.htm">MsgBox</a>, <a href="InputBox.htm">InputBox</a>, <a href="FileSelect.htm">FileSelect</a>, <a href="DirSelect.htm">DirSelect</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>TrayTip "Multiline`nText", "My Title", "Iconi Mute"</pre>
</div>


<div class="ex" id="ExDisplayTime">
<p><a href="#ExDisplayTime">#2</a>: To have more precise control over the display time without having to use Sleep (which stops the current thread):</p>
<pre>#Persistent
TrayTip "This will be displayed for 5 seconds.", "Timed TrayTip"
SetTimer "HideTrayTip", -5000

HideTrayTip() {  <em>; NOTE: For Windows 10, replace this function with the one defined <a href="#Hide">above</a>.</em>
    TrayTip
}
</pre>
</div>

<div class="ex" id="ExPermanent">
<p><a href="#ExPermanent">#3</a>: To have a TrayTip permanently displayed, use a timer to refresh it periodically. NOTE: This probably won't work well on Windows 10 for <a href="#Windows10">reasons described above</a>.</p>
<pre>#Persistent
SetTimer "RefreshTrayTip", 1000
RefreshTrayTip  <em>; Call it once to get it started right away.</em>

RefreshTrayTip()
{
    TrayTip "This is a more permanent TrayTip.", "Refreshed TrayTip", "Mute"
}</pre>
</div>

</body>
</html>